﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Ledict.Core.Data;
using System.Data.Common;
using Ledict.ConditionExtract.Model;
using Ledict.ConditionExtract.Common;
using LdtJudge.DatabaseHandle;

namespace Ledict.ConditionExtract.DAL
{
    /// <summary>
    /// 法定情节调节法定刑表
    /// </summary>
    public class XF_Major_AddpenaltyDAL
    {
        private string DbName;
        public XF_Major_AddpenaltyDAL()
        {
            DbName = "JudgeDoc";
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(XF_Major_AddpenaltyModel model)
        {
            string sql=string.Format(@"insert into XF_Major_Addpenalty(
			MA_ID,GM_ID,MA_TypeID,MA_Minimum,MA_Supreme,MA_Penalunit,MA_ApplicationID,MA_Optional,MA_ProvInID)
			values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')", model.MA_ID,model.GM_ID,model.MA_TypeID,model.MA_Minimum,model.MA_Supreme,model.MA_Penalunit,model.MA_ApplicationID,model.MA_Optional,model.MA_ProvInID);
            Database oBase = DatabaseFactory.CreateDatabase(DbName);
            DbCommand oCmd = oBase.GetSqlStringCommand(sql);
            if (oBase.ExecuteNonQuery(oCmd) > 0)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string maId)
        {
            string sql = string.Format(@" delete from XF_Major_Addpenalty where MA_ID ='{0}' ", maId);           
            Database oBase = DatabaseFactory.CreateDatabase(DbName);
            DbCommand oCmd = oBase.GetSqlStringCommand(sql);
            if (oBase.ExecuteNonQuery(oCmd) > 0)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 删除多条附加刑数据
        /// </summary>
        public bool DeleteMaIds(string maIds)
        {
            string sql = string.Format(@" delete from XF_Major_Addpenalty where MA_ID in ({0}) ", maIds);
            Database oBase = DatabaseFactory.CreateDatabase(DbName);
            DbCommand oCmd = oBase.GetSqlStringCommand(sql);
            if (oBase.ExecuteNonQuery(oCmd) > 0)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 获取法定情节调节法定刑数据
        /// </summary>
        /// <param name="ccid">节点信息</param>
        /// <returns></returns>
        public DataTable GetAdjustment(string ccid)
        {
            string sql = string.Format(@" SELECT *  FROM [Ldt_JudgeDocSystem].[dbo].[XF_Major_Addpenalty] where MA_ID='{0}' ", ccid);
            Database oBase = DatabaseFactory.CreateDatabase(DbName);
            DbCommand oCmd = oBase.GetSqlStringCommand(sql.ToString());
            var otB = oBase.ExecuteDataSet(oCmd).Tables[0];
            if (otB.Rows.Count > 0)
            {
                return otB;
            }
            return new DataTable();
        }

        /// <summary>
        /// 修改字典值名称，通过Am_ID
        /// </summary>
        public bool UpdateName(XF_Major_AddpenaltyModel model)
        {
            string sql = string.Format(@" update XF_Major_Addpenalty set GM_ID='{0}',MA_TypeID='{1}',MA_Minimum='{2}',MA_Supreme='{3}',MA_Penalunit='{4}',MA_ApplicationID='{5}',MA_Optional='{6}',MA_ProvInID='{7}' where MA_ID='{8}' ", 
                model.GM_ID, model.MA_TypeID, model.MA_Minimum, model.MA_Supreme,model.MA_Penalunit,model.MA_ApplicationID,model.MA_Optional,model.MA_ProvInID,model.MA_ID);            
            Database oBase = DatabaseFactory.CreateDatabase(DbName);
            DbCommand oCmd = oBase.GetSqlStringCommand(sql);
            if (oBase.ExecuteNonQuery(oCmd) > 0)
            {
                return true;
            }
            return false;
        }

        

    }
}
